/**
 * 响应式: 核心
 * ref() computed() reactive() readonly()
 * watchEffect() watchPostEffect() watchSyncEffect() watch()
 */

import { trigger } from "./../compiler.js";

export const ref = (value, key) => {
  trigger(key, value);
  const target = { value, key }; // 目标对象
  const handler = {
    get(target, propKey, receiver) {
      return Reflect.get(target, propKey, receiver);
    },
    set(target, propKey, value, receiver) {
      trigger(key, value);
      return Reflect.set(target, propKey, value, receiver);
    },
  }; // 处理器对象
  return new Proxy(target, handler); // 创建代理对象
};
